/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import java.io.Serializable;
import javax.persistence.*;
import org.ipti.br.tag.util.EncryptionUtil;


/**
 *
 * @author root
 */
@Entity
public class Hb extends AbstractEntity implements Serializable{

    @Column(columnDefinition="Decimal(10,2)", nullable=false)
    private Float hemoglobineTax;
    
    private Byte ordernation;
    
    private Boolean anemic;
    
    @ManyToOne
    @JoinColumn(nullable=false)
    private Campaign campaign;
     
    @ManyToOne
    @JoinColumn(nullable=false)
    private Human human;

    public Hb() {
        this.anemic = false;
    }

    public Hb(Float hemoglobineTax, Byte ordernation, Campaign campaign, Human human) {
        this.hemoglobineTax = hemoglobineTax;
        this.ordernation = ordernation;
        this.campaign = campaign;
        this.human = human;
        this.anemic = false;
    }
    
    @Override
    public void generateHash() {
        if ( getId() == null) {
            String hash =""
                    + ((this.getCampaign() != null) ? this.getCampaign().getId(): "") + ""
                    + ((this.getOrdernation() != null) ? this.getOrdernation(): "") + ""
                    + ((this.getAnemic() != null) ? this.getAnemic(): "") + ""
                    + ((this.getHuman() != null) ? this.getHuman().getId(): "");
            this.setId( Long.valueOf( EncryptionUtil.encrypt(hash).hashCode()));
        }
    }

    public Float getHemoglobineTax() {
        return hemoglobineTax;
    }

    public void setHemoglobineTax(Float hemoglobineTax) {
        this.hemoglobineTax = hemoglobineTax;
    }

    public Byte getOrdernation() {
        return ordernation;
    }

    public void setOrdernation(Byte ordernation) {
        this.ordernation = ordernation;
    }

    public Boolean getAnemic() {
        return anemic;
    }

    public void setAnemic(Boolean anemic) {
        this.anemic = anemic;
    }

    public Campaign getCampaign() {
        return campaign;
    }

    public void setCampaign(Campaign campaign) {
        this.campaign = campaign;
    }

    public Human getHuman() {
        return human;
    }

    public void setHuman(Human human) {
        this.human = human;
    }
}
